$('#leftP').click(function () {
    $('#index').removeClass('moveLeft').addClass('moveRight');
    $('#leftPage').removeClass('moveL').addClass('moveR');
    $('.shade').show();

});
$('.shade').click(function () {
    $(this).hide();
    $('#index').removeClass('moveRight').addClass('moveLeft');
    $('#leftPage').removeClass('moveR').addClass('moveL');

});
function getSlideAngle(dx, dy) {
    return (Math.atan2(dy, dx) * 180 / Math.PI)
}
function getslideDirection(tX, tY, eX, eY) {     //1为右，2为左，3为下，4为上 ，0不动
    var dx = eX - tX;
    var dy = eY - tY;
    var result = 0;
    if (Math.abs(dx) < 2 && Math.abs(dy) < 2) {
        return result
    }
    var angle = getSlideAngle(dx, dy);
    if (angle >= -45 && angle <= 45) {
        result = 1;
    } else if (angle >= 135 && angle <= 180 || angle <= -135 && angle >= -180) {
        result = 2;
    } else if (angle > 45 && angle < 135) {
        result = 3;
    } else if (angle < -45 && angle > -135) {
        result = 4;
    }
    return result
}

$(window).bind({
    touchstart: function (e) {
        var t = new Date();
        startTime = t.getTime();

        var touch = e.originalEvent.targetTouches[0];
        startX = Number(touch.pageX);
        startY = Number(touch.pageY);

    },
    touchmove: function (e) {
        var touch = e.originalEvent.targetTouches[0];
        moveX = Number(touch.pageX);
        moveY = Number(touch.pageY);
        var direction = getslideDirection(startX, startY, moveX, moveY);
        if (direction == 1) {
            console.log('右')
        } else if (direction == 2) {
            console.log('左')
        } else if (direction == 3) {
            console.log('下')
        } else if (direction == 4) {
            console.log('上')
        }


        // console.log(moveX-startX);
        // if (moveX - startX > 0){
        //       console.log(moveX - startX)
        // }else if (moveX - startX < 0){
        //     console.log(moveX - startX)
        // }

    },
    touchend: function () {
        var t = new Date();
        endTime = t.getTime();
        if (endTime - startTime > 140) {

            // console.log(moveX - startX)


        }

    }
});
$(".toLeft").bind({
    touchstart: function (e) {
        var touch = e.originalEvent.targetTouches[0];


    },
    touchmove: function (e) {

    },
    touchend: function () {

    }
})
